package com.example.bilibili.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.bilibili.domain.Bullet;
import com.example.bilibili.domain.Comment;
import com.example.bilibili.service.BulletService;
import com.example.bilibili.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BulletController {
    @Autowired
    private BulletService bulletService;
    @Autowired
    private CommentService commentService;
    @RequestMapping("/findAllBullet")
    public Object findAllBullet(){
        QueryWrapper<Bullet> qw= new QueryWrapper<>();
        qw.select("id","content","userid","videoid");
        return bulletService.list(qw);
    }

    //通过userid查找弹幕
    @RequestMapping("/findBulletByid")
    public Object findBulletByname(String userId){
        QueryWrapper<Bullet> qw= new QueryWrapper<>();
        qw.select("id","content","userId","videoId").eq("userId",userId);
        return bulletService.list(qw);
    }

    //通过Id删除弹幕
    @RequestMapping("/deleteBulletByid")
    public int deleteBulletByID(int id){
        QueryWrapper qw= new QueryWrapper();
        qw.eq("id",id);
        return bulletService.remove(qw)?1:0;
    }

    //查找所有评论
    @RequestMapping("/findAllComment")
    public Object findAllComment(){
        QueryWrapper<Comment> qw= new QueryWrapper<>();
        qw.select("id","content","userid","videoid");
        return commentService.list(qw);
    }

    //通过userid查找评论。
    @RequestMapping("/findCommentByid")
    public Object findCommentByname(String userId){
        QueryWrapper<Comment> qw= new QueryWrapper<>();
        qw.select("id","content","userId","videoId").eq("userId",userId);
        return commentService.list(qw);
    }

    //通过id删除评论
    @RequestMapping("/deleteCommentByid")
    public int deleteCommentByID(int id){
        QueryWrapper<Comment> qw= new QueryWrapper();
        qw.eq("id",id);
        return commentService.remove(qw)?1:0;
    }

}
